package com.xuqing.easymessage;


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import android.content.Context;

/**
 * 福利类
 */
public class SaveObjectHelper {
	public static void saveObject(Context context,String name,Object obj){  
        FileOutputStream fos = null;  
        ObjectOutputStream oos = null;  
        try {  
            fos = context.openFileOutput(name, Context.MODE_PRIVATE);  
            oos = new ObjectOutputStream(fos);  
            oos.writeObject(obj);  
        } catch (Exception e) {  
            e.printStackTrace();  
        } finally {  
            if (fos != null){  
                try {  
                    fos.close();  
                } catch (IOException e) {  
                    e.printStackTrace();  
                }  
            }  
            if (oos != null){  
                try {  
                    oos.close();  
                } catch (IOException e) {  
                    e.printStackTrace();  
                }  
            }  
        }  
    }  
	
	public static Object getObject(Context context,String name){  
	        FileInputStream fis = null;  
	        ObjectInputStream ois = null;  
	        try {  
	            fis = context.openFileInput(name);  
	            ois = new ObjectInputStream(fis);  
	            return ois.readObject();  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        } finally {  
	            if (fis != null){  
	                try {  
	                    fis.close();  
	                } catch (IOException e) {  
	                    e.printStackTrace();  
	                }  
	            }  
	            if (ois != null){  
	                try {  
	                    ois.close();  
	                } catch (IOException e) {  
	                    e.printStackTrace();  
	                }  
	            }  
	        }  
	        return null;  
	    }  
}
